const {ipcRenderer} = require('electron');

let showTime = document.getElementById('showTime');

window.addEventListener('DOMContentLoaded',async()=>{
    let time_h_left;
    let time_m_left;
    let time_s_left;
    ipcRenderer.on('new-win-sleep-returnHour',async(event,data)=>{
        time_h_left = data
        console.log('sleep time h:',data)
    })
    ipcRenderer.on('new-win-sleep-returnMinue',async(event,data)=>{
        time_h_left = data
        console.log('sleep time m:',data)
    })
    let timeIndex = 90*60; //测试,先10秒
    
    let time = setInterval(()=>{
        let time_now = new Date();
        let time_now_h = time_now.getHours();
        let time_now_m = time_now.getMinutes();
        let time_now_s = time_now.getSeconds();
        timeIndex -= 1;
        time_h_left = parseInt(timeIndex / 60 / 60);
        time_m_left = parseInt(timeIndex / 60 % 60);
        time_s_left = parseInt(timeIndex % 60);
        showTime.innerText = time_s_left
        showTime.innerText = `${time_h_left}:${time_m_left}:${time_s_left}`;
        if(timeIndex == 0){
            ipcRenderer.send('mainwin-new-win')
            ipcRenderer.send('getTianQi')
            clearInterval(time);
            ipcRenderer.send('sleeptime-close')
        }
    },1000);
})

let i = 0
const change = async() => {
    const pinnedImage = document.getElementById("pinnedImage");
    console.log(pinnedImage.src,i)
    if(i == 0){
        pinnedImage.style.transform = 'rotate3d(0,0,1,-45deg)';
        ipcRenderer.send('sleeptime-top')
        i = 1;
    }else{
        // pinnedImage.src = "images/Pinned_xie.svg"
        pinnedImage.style.transform = 'rotate3d(0,0,1,0deg)';
        ipcRenderer.send('sleeptime-no-top')
        i = 0;
    }
}

const clickClose = async() => {
    ipcRenderer.send('sleeptime-close');
}